/*
 * @Descripttion:
 * @version:
 * @Author: kl2018
 * @Date: 2020-02-28 17:37:08
 * @LastEditors: kl2018
 * @LastEditTime: 2020-06-04 09:31:13
 */
import { Modal } from 'antd';
import { WeaLocaleProvider } from 'ecCom';

const { getLabel } = WeaLocaleProvider;
const confirm = Modal.confirm;

export const affirmDeleted = (onOkFunc, { title = '', content = '', okText = '', cancelText = '', onCancel = null } = {}) => {
  confirm({
    title: title || getLabel('131329', '信息确认'),
    content: content || getLabel('33435', '确定要删除选中的记录吗？'),
    okText: okText || getLabel('163', '是'),
    cancelText: cancelText || getLabel('30587', '否'),
    onOk: () => onOkFunc(),
    onCancel: () => onCancel && onCancel(),
  });
};

export const validateForm = (form, success, fail) => {
  form.validate().then((f) => {
    if (f.isValid) {
      success && success();
    } else {
      fail ? fail() : f.showErrors();
    }
  });
};
